/**
 * Created by gongxun on 17/6/17.
 */

var KwxRewardLayer = KwxBaseLayer.extend({
    Panel_move : null,
    Panel_hide : null,
    Text_num : null,
    ctor: function () {
        this._super();
        this.loadCocostudio("res/ccs/KwxRewardLayer.json");
        mo.gameHelper.fixIosText(this.ccsNode);

        this.Panel_move = mo.seekWidgetByName(this.ccsNode, "Panel_move");
        this.Panel_hide = mo.seekWidgetByName(this.ccsNode, "Panel_hide");
        this.Text_num = mo.seekWidgetByName(this.ccsNode, "Text_num");
    },

    startAction : function(num, toPos, toPlayer){
        //动画
        mo.seekWidgetByName(this.ccsNode, "Image_light").runAction(cc.repeatForever(
            cc.sequence(
                cc.rotateBy(6, 360)
            )
        ));

        mo.seekWidgetByName(this.ccsNode, "Image_wing_r").runAction(cc.repeatForever(
            cc.sequence(
                cc.rotateTo(0.4, -15),
                cc.rotateTo(0.4, 15)
            )
        ));

        mo.seekWidgetByName(this.ccsNode, "Image_wing_l").runAction(cc.repeatForever(
            cc.sequence(
                cc.rotateTo(0.4, 15),
                cc.rotateTo(0.4, -15)
            )
        ));

        mo.gameHelper.setTextString(this.Text_num, "" + num);

        this.Panel_move.setPosition(cc.p(mo.curSize.x / 2, mo.curSize.y / 2));
        var that = this;
        this.Panel_move.runAction(cc.sequence(
            cc.delayTime(1.5),
            cc.callFunc(function(){
                that.Panel_hide.setVisible(false);
            }),
            cc.spawn(
                cc.moveTo(0.3, toPos),
                cc.scaleTo(0.3, 0.2)
            ),
            cc.delayTime(1),
            cc.callFunc(function(){
                that.removeFromParent();
                if (toPlayer == 0){
                    mo.showRoomMsgShow("恭喜你获取游戏红包，请在礼包界面中查看领取方式");
                }
            })
        ));
    }
});
